package start.demo01.fileIO;

import java.io.*;
import java.util.Scanner;

public class Task06 {
    public static void main(String[] args) throws IOException {
        String path="D:/Letter";
        String name="Letter.txt";
        File dir=new File(path);
        dir.mkdir();
        File file = file=new File(dir,name);;
        Scanner input=new Scanner(System.in);
        System.out.println("1.撰写请假条");
        System.out.println("2.查看请假条");
        if(input.nextInt()==1){
            System.out.println("1.病假");
            System.out.println("2.事假");
            int f=input.nextInt();
            file.createNewFile();
            System.out.print("请假人:");
            String man=input.next();
            System.out.print("日期:");
            try(BufferedWriter writer=new BufferedWriter(new FileWriter(file));){
                writer.write("请假人  "+man);
                writer.newLine();
                writer.write("请假日期  "+input.next());
                writer.newLine();
                if(f==1)
                    writer.write("我因发烧，请假一天");
                else
                    writer.write("参见婚礼，于6.10请假一天");
            }
        }else{
            try(
                BufferedReader reader=new BufferedReader(new FileReader(file));){
                int val;
                while((val=reader.read())!=-1){
                    System.out.print((char)val);
                }
            }
        }
    }
}
